using System;
using UnityEngine;

public class ShopCoinUI : GameUI
{
	public UILabel lbCoin;

	public InappCoinData[] data;

	public ShopCoinPrefab[] prefabs;

	public GameObject coinTopRight;

	public IAPManager inappManager;

	private void Awake()
	{
		PersistenData.OnCoinChange = (Action<int>)Delegate.Combine(PersistenData.OnCoinChange, new Action<int>(ShowCoin));
		inappManager.onPurchaseSuccess += OnPurchaseSuccess;
	}

	private void Start()
	{
		ShowCoin(PersistenData.Coin);
		BindCoinPack();
	}

	private void ShowCoin(int coin)
	{
		lbCoin.text = coin.ToString("0");
	}

	private void BindCoinPack()
	{
		for (int i = 0; i < prefabs.Length; i++)
		{
			prefabs[i].SetItem(data[i].coin, data[i].price, data[i].sku, this);
		}
	}

	public void PurchaseCoin(string sku)
	{
		AdManager.Instance.ShowVideo(() =>
		{
			OnPurchaseSuccess(sku);
		});
	}

	private void OnPurchaseSuccess(string sku)
	{
		InappCoinData[] array = data;
		int num = 0;
		InappCoinData inappCoinData;
		while (true)
		{
			if (num < array.Length)
			{
				inappCoinData = array[num];
				if (inappCoinData.sku == sku)
				{
					break;
				}
				num++;
				continue;
			}
			return;
		}
		PersistenData.Coin += inappCoinData.coin;
	}

	public void ShowCoinTopRight(bool flag)
	{
		coinTopRight.SetActive(flag);
	}
}
